import {
  HTTP
} from '../utils/http.js';
import utils from '../utils/util';

class orderModel extends HTTP {

  // 下单
  apiAddOrder(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/add',
      method: 'post',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    }, 'postJson')
  }

  // 提交订单(组订单)
  apiSubmitOrderMs(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/submitWithGroupNo',
      method: 'post',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    })
  } 
  // new提交订单(组订单)
  apiSubmitOrderMsV2(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/submitWithGroupNo/v2',
      method: 'post',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    },'postJson')
  }

  // 订单详情(组订单)
  apiOrderDetailMs(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/findByIdByGroupId',
      method: 'get',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    })
  }

  // 微信支付(组订单支付)
  releaseWXPayMs(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/pay/wx/release/shopOrderNo',
      method: 'post',
      data: data,
      success: (res) => {
        sCallback(res)
      }

    })
  }
  // 假的微信支付(组订单支付)
  payNotifytestMs(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/payTestWithGroupNo',
      method: 'post',
      data: data,
      success: (res) => {
        sCallback(res)
      }

    })
  }

  // 提交订单(订单)
  apiSubmitOrder(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/submit',
      method: 'post',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    })
  }
  // new提交订单(订单)
  apiSubmitOrderV2(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/submit/v2',
      method: 'post',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    },'postJson')
  }

  // 订单详情(订单)
  apiOrderDetail(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/findById',
      method: 'get',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    })
  }

  // 微信支付(订单支付)
  releaseWXPay(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/pay/wx/release/groupNo',
      method: 'post',
      data: data,
      success: (res) => {
        sCallback(res)
      }

    })
  }
  // 假的微信支付(订单支付)
  payNotifytest(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/payTest',
      method: 'post',
      data: data,
      success: (res) => {
        sCallback(res)
      }

    })
  }

  // 订单卡片列表
  apiorderCaPage(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/listPage/time',
      method: 'get',
      data: data,
      success: (res) => {
        if(res.code == 200)
          sCallback(res.data)
        else 
          utils.msg(res.msg)
      }

    })
  }

  // 订单列表
  apiOrderPage(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/listPage',
      method: 'get',
      data: data,
      success: (res) => {
        if(res.code == 200)
          sCallback(res.data)
        else 
          utils.msg(res.msg)
      }

    })
  }

  // 确认收货
  apiReceiveOrder(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/receive',
      method: 'post',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    })
  }

  // 确认订单
  apiConfirmOrder(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/confirmOrder',
      method: 'post',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    })
  }

  // 取消订单
  apiCancelOrder(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/cancel',
      method: 'post',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    })
  }

  // 删除购物车
  carDelete(data, sCallback) {
    this.request({
      url: 'canteen/shop/car/delete',
      method: 'post',
      data: data,
      success: (res) => {
        sCallback(res)
        // if (res.code == 200) {
        //   sCallback(res.data)
        // } else {
        //   utils.msg(res.msg)
        // }
      }
    })
  }

  // 导出
  exportOrder(data, sCallback){
    this.downLoadFile({
      url: 'canteen/shop/order/exportOrder'+data,
      success: (res) => {
        sCallback(res)
      }
    })
  }

  // 再次购买
  carAddBatch(data, sCallback) {
    this.request({
      url: 'canteen/shop/car/purchase/re',
      method: 'post',
      data: data,
      success: (res) => {
        sCallback(res)
      }
    })
  }

  // 修改订单
  updateOrder(data, sCallback) {
    this.request({
      url: 'canteen/shop/order/updateOrder',
      method: 'post',
      data: data,
      success: (res) => {
        if (res.code == 200) {
          sCallback(res.data)
        } else {
          utils.msg(res.msg)
        }
      }
    },'postJson')
  }


}
export {
  orderModel
}